package com.stock.common.utils;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;

/**
 * @author zy
 * @date 2019-03-18 14:35
 **/
public class GeneratorUtils {

    /**
     * 生成订单号
     * @return 订单号
     */
    public static String generatorOrderNumber() {

        String date = new SimpleDateFormat("yyyyMMdd").format(new Date());
        String orderConstant01 = "00100";
        String twoRandom01 = generatorTowRandom();
        String orderConstant02 = "00";
        String seconds = new SimpleDateFormat("HHmmss").format(new Date());
        String twoRandom02 = generatorTowRandom();
        return date + orderConstant01 + twoRandom01 + orderConstant02 + seconds + twoRandom02;
    }

    /**
     * 生成两位随机数
     * @return String
     */
    private static String generatorTowRandom() {
        Random random = new Random();
        String result = String.valueOf(random.nextInt(100));
        if (result.length() == 1) {
            result = "0" + result;
        }
        return result;
    }

    public static void main(String[] args){
        System.out.println(generatorOrderNumber());
    }
}
